class Solution:
    def isScramble(self, s1: str, s2: str) -> bool:
        for index, word in enumerate(s1):
            s2 = s2.replace(word, str(index), 1)
        if not s2.isdecimal():
            return False
        start_index = s2.index("0")
        end_index = s2.index(str(len(s1) - 1))
        word_zuo = s2[:start_index+1]
        word_you = s2[end_index:]
        for i in range(len(word_zuo)):
            if str(i) not in word_zuo:
                return False
        for j in range(end_index, len(s2)):
            if str(j) not in word_you:
                return False
        return True


a = Solution()
print(a.isScramble(s1="great", s2="rgeat"))
print(a.isScramble(s1="abcde", s2="caebd"))
print(a.isScramble(s1="abb", s2="bba"))
